<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/blog/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/blog/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/blog/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/blog/images/logo.svg" color="#222">

<link rel="stylesheet" href="/blog/css/main.css">


<link rel="stylesheet" href="/blog/lib/font-awesome/css/all.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"dttx123.gitee.io","root":"/blog/","scheme":"Gemini","version":"8.0.0-rc.2","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="IT">
<meta property="og:type" content="website">
<meta property="og:title" content="Starry Night">
<meta property="og:url" content="http://dttx123.gitee.io/page/3/index.html">
<meta property="og:site_name" content="Starry Night">
<meta property="og:description" content="IT">
<meta property="og:locale" content="zh_CN">
<meta property="article:author" content="大春哥">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="http://dttx123.gitee.io/page/3/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : true,
    isPost : false,
    lang   : 'zh-CN'
  };
</script>

  <title>Starry Night</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
        <span class="toggle-line toggle-line-first"></span>
        <span class="toggle-line toggle-line-middle"></span>
        <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/blog/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">Starry Night</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">这就朕为你打下的江山</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/blog/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/blog/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/blog/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/blog/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/blog/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content index posts-expand">
            
      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://dttx123.gitee.io/2017/07/04/javaScript/%E5%B8%B8%E7%94%A8%E7%9A%84%E5%B0%8F%E6%96%B9%E6%B3%95/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/blog/images/avatar.jpg">
      <meta itemprop="name" content="大春哥">
      <meta itemprop="description" content="IT">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Starry Night">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/blog/2017/07/04/javaScript/%E5%B8%B8%E7%94%A8%E7%9A%84%E5%B0%8F%E6%96%B9%E6%B3%95/" class="post-title-link" itemprop="url">常用的小方法</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2017-07-04 00:00:00" itemprop="dateCreated datePublished" datetime="2017-07-04T00:00:00+08:00">2017-07-04</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2020-07-06 23:10:27" itemprop="dateModified" datetime="2020-07-06T23:10:27+08:00">2020-07-06</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/js%E5%9F%BA%E7%A1%80/" itemprop="url" rel="index"><span itemprop="name">js基础</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h1 id="常用的小方法"><a href="#常用的小方法" class="headerlink" title="常用的小方法"></a>常用的小方法</h1><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> *</span></span><br><span class="line"><span class="comment"> *  <span class="doctag">@classDesc </span>核心js基类,提供全局可用api</span></span><br><span class="line"><span class="comment"> *  <span class="doctag">@namespace <span class="variable">ZA</span></span></span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> Za = &#123;</span><br><span class="line">  <span class="comment">/**</span></span><br><span class="line"><span class="comment">   * 转换为字符</span></span><br><span class="line"><span class="comment">   * <span class="doctag">@param </span>v &#123;object&#125;</span></span><br><span class="line"><span class="comment">   * <span class="doctag">@returns <span class="type">&#123;string&#125;</span></span></span></span><br><span class="line"><span class="comment">   */</span></span><br><span class="line">  toString: <span class="function"><span class="keyword">function</span> (<span class="params">v</span>) </span>&#123;</span><br><span class="line">    <span class="keyword">return</span> <span class="built_in">Object</span>.prototype.toString.apply(v);</span><br><span class="line">  &#125;,</span><br><span class="line">  <span class="comment">/**</span></span><br><span class="line"><span class="comment">   * 判断值是否已定义</span></span><br><span class="line"><span class="comment">   * <span class="doctag">@param </span>v &#123;*&#125;</span></span><br><span class="line"><span class="comment">   * <span class="doctag">@returns <span class="type">&#123;boolean&#125;</span></span></span></span><br><span class="line"><span class="comment">   */</span></span><br><span class="line">  isDefined: <span class="function"><span class="keyword">function</span> (<span class="params">v</span>) </span>&#123;</span><br><span class="line">    <span class="keyword">return</span> <span class="keyword">typeof</span> v !== <span class="string">'undefined'</span>;</span><br><span class="line">  &#125;,</span><br><span class="line">  <span class="comment">/**</span></span><br><span class="line"><span class="comment">   * 是否为空</span></span><br><span class="line"><span class="comment">   * <span class="doctag">@param </span>v  &#123;*&#125; 值</span></span><br><span class="line"><span class="comment">   * <span class="doctag">@param </span>allowBlank &#123;boolean&#125; 是否允许空</span></span><br><span class="line"><span class="comment">   * <span class="doctag">@returns <span class="type">&#123;boolean|*&#125;</span></span></span></span><br><span class="line"><span class="comment">   */</span></span><br><span class="line">  isEmpty: <span class="function"><span class="keyword">function</span> (<span class="params">v, allowBlank</span>) </span>&#123;</span><br><span class="line">    <span class="keyword">return</span> v === <span class="literal">null</span> || v === <span class="literal">undefined</span></span><br><span class="line">      || <span class="built_in">String</span>(v).toUpperCase() === <span class="string">'NULL'</span></span><br><span class="line">      || ((Za.isArray(v) &amp;&amp; !v.length))</span><br><span class="line">      || (!allowBlank ? v === <span class="string">''</span> : <span class="literal">false</span>)</span><br><span class="line">      || (Za.isObject(v) &amp;&amp; <span class="built_in">JSON</span>.stringify(v) === <span class="string">'&#123;&#125;'</span>)</span><br><span class="line">  &#125;,</span><br><span class="line"></span><br><span class="line">  <span class="comment">/**</span></span><br><span class="line"><span class="comment">   * 是否是数组</span></span><br><span class="line"><span class="comment">   * <span class="doctag">@param <span class="variable">v</span></span></span></span><br><span class="line"><span class="comment">   * <span class="doctag">@returns <span class="type">&#123;boolean&#125;</span></span></span></span><br><span class="line"><span class="comment">   */</span></span><br><span class="line">  isArray: <span class="function"><span class="keyword">function</span> (<span class="params">v</span>) </span>&#123;</span><br><span class="line">    <span class="keyword">return</span> Za.toString(v) === <span class="string">'[object Array]'</span>;</span><br><span class="line">  &#125;,</span><br><span class="line">  <span class="comment">/**</span></span><br><span class="line"><span class="comment">   * 是否是日期</span></span><br><span class="line"><span class="comment">   * <span class="doctag">@param <span class="variable">v</span></span></span></span><br><span class="line"><span class="comment">   * <span class="doctag">@returns <span class="type">&#123;boolean&#125;</span></span></span></span><br><span class="line"><span class="comment">   */</span></span><br><span class="line">  isDate: <span class="function"><span class="keyword">function</span> (<span class="params">v</span>) </span>&#123;</span><br><span class="line">    <span class="keyword">return</span> Za.toString(v) === <span class="string">'[object Date]'</span>;</span><br><span class="line">  &#125;,</span><br><span class="line">  <span class="comment">/**</span></span><br><span class="line"><span class="comment">   * 是否是对象</span></span><br><span class="line"><span class="comment">   * <span class="doctag">@param <span class="variable">v</span></span></span></span><br><span class="line"><span class="comment">   * <span class="doctag">@returns <span class="type">&#123;boolean&#125;</span></span></span></span><br><span class="line"><span class="comment">   */</span></span><br><span class="line">  isObject: <span class="function"><span class="keyword">function</span> (<span class="params">v</span>) </span>&#123;</span><br><span class="line">    <span class="keyword">return</span> !!v &amp;&amp; Za.toString(v) === <span class="string">'[object Object]'</span>;</span><br><span class="line">  &#125;,</span><br><span class="line">  <span class="comment">/**</span></span><br><span class="line"><span class="comment">   * 字符串是否是对象</span></span><br><span class="line"><span class="comment">   * <span class="doctag">@param <span class="variable">str</span></span></span></span><br><span class="line"><span class="comment">   * <span class="doctag">@returns <span class="type">&#123;boolean&#125;</span></span></span></span><br><span class="line"><span class="comment">   */</span></span><br><span class="line">  isJSON(str) &#123;</span><br><span class="line">    <span class="keyword">if</span> (<span class="keyword">typeof</span> str == <span class="string">'string'</span>) &#123;</span><br><span class="line">      <span class="keyword">try</span> &#123;</span><br><span class="line">        <span class="keyword">var</span> obj = <span class="built_in">JSON</span>.parse(str);</span><br><span class="line">        <span class="keyword">if</span> (<span class="keyword">typeof</span> obj == <span class="string">'object'</span> &amp;&amp; obj) &#123;</span><br><span class="line">          <span class="keyword">return</span> <span class="literal">true</span>;</span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">          <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">      &#125; <span class="keyword">catch</span> (e) &#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;,</span><br><span class="line">  <span class="comment">/**</span></span><br><span class="line"><span class="comment">   * 是否是函数</span></span><br><span class="line"><span class="comment">   * <span class="doctag">@param <span class="variable">v</span></span></span></span><br><span class="line"><span class="comment">   * <span class="doctag">@returns <span class="type">&#123;boolean&#125;</span></span></span></span><br><span class="line"><span class="comment">   */</span></span><br><span class="line">  isFunction: <span class="function"><span class="keyword">function</span> (<span class="params">v</span>) </span>&#123;</span><br><span class="line">    <span class="keyword">return</span> Za.toString(v) === <span class="string">'[object Function]'</span>;</span><br><span class="line">  &#125;,</span><br><span class="line">  <span class="comment">/**</span></span><br><span class="line"><span class="comment">   * 是否是数值型</span></span><br><span class="line"><span class="comment">   * <span class="doctag">@param <span class="variable">v</span></span></span></span><br><span class="line"><span class="comment">   * <span class="doctag">@returns <span class="type">&#123;boolean&#125;</span></span></span></span><br><span class="line"><span class="comment">   */</span></span><br><span class="line">  isNumber: <span class="function"><span class="keyword">function</span> (<span class="params">v</span>) </span>&#123;</span><br><span class="line">    <span class="keyword">return</span> <span class="keyword">typeof</span> v === <span class="string">'number'</span> &amp;&amp; <span class="built_in">isFinite</span>(v);</span><br><span class="line">  &#125;,</span><br><span class="line">  <span class="comment">/**</span></span><br><span class="line"><span class="comment">   * 是否是字符型</span></span><br><span class="line"><span class="comment">   * <span class="doctag">@param <span class="variable">v</span></span></span></span><br><span class="line"><span class="comment">   * <span class="doctag">@returns <span class="type">&#123;boolean&#125;</span></span></span></span><br><span class="line"><span class="comment">   */</span></span><br><span class="line">  isString: <span class="function"><span class="keyword">function</span> (<span class="params">v</span>) </span>&#123;</span><br><span class="line">    <span class="keyword">return</span> <span class="keyword">typeof</span> v === <span class="string">'string'</span>;</span><br><span class="line">  &#125;,</span><br><span class="line">  <span class="comment">/**</span></span><br><span class="line"><span class="comment">   * 是否是布尔型</span></span><br><span class="line"><span class="comment">   * <span class="doctag">@param <span class="variable">v</span></span></span></span><br><span class="line"><span class="comment">   * <span class="doctag">@returns <span class="type">&#123;boolean&#125;</span></span></span></span><br><span class="line"><span class="comment">   */</span></span><br><span class="line">  isBoolean: <span class="function"><span class="keyword">function</span> (<span class="params">v</span>) </span>&#123;</span><br><span class="line">    <span class="keyword">return</span> <span class="keyword">typeof</span> v === <span class="string">'boolean'</span>;</span><br><span class="line">  &#125;,</span><br><span class="line">  <span class="comment">/**</span></span><br><span class="line"><span class="comment">   * 是否是原始类型</span></span><br><span class="line"><span class="comment">   * <span class="doctag">@param <span class="variable">v</span></span></span></span><br><span class="line"><span class="comment">   * <span class="doctag">@returns <span class="type">&#123;*|boolean&#125;</span></span></span></span><br><span class="line"><span class="comment">   */</span></span><br><span class="line">  isPrimitive: <span class="function"><span class="keyword">function</span> (<span class="params">v</span>) </span>&#123;</span><br><span class="line">    <span class="keyword">return</span> Za.isString(v) || Za.isNumber(v) || Za.isBoolean(v);</span><br><span class="line">  &#125;,</span><br><span class="line">  <span class="comment">/**</span></span><br><span class="line"><span class="comment">   * 是否是URL</span></span><br><span class="line"><span class="comment">   * <span class="doctag">@param <span class="variable">v</span></span></span></span><br><span class="line"><span class="comment">   * <span class="doctag">@returns <span class="type">&#123;boolean&#125;</span></span></span></span><br><span class="line"><span class="comment">   */</span></span><br><span class="line">  isUrl: <span class="function"><span class="keyword">function</span> (<span class="params">v</span>) </span>&#123;</span><br><span class="line">    <span class="keyword">return</span> <span class="regexp">/(((^https?)|(^ftp)):\/\/((([\-\w]+\.)+\w&#123;2,3&#125;(\/[%\-\w]+(\.\w&#123;2,&#125;)?)*(([\w\-\.\?\\\/+@&amp;#;`~=%!]*)(\.\w&#123;2,&#125;)?)*)|(localhost|LOCALHOST|127.0.0.1))\/?)/i</span></span><br><span class="line">      .test(v);</span><br><span class="line">  &#125;,</span><br><span class="line"></span><br><span class="line">  <span class="comment">/**</span></span><br><span class="line"><span class="comment">   * 返回parameters参数 特指页面跳转间传递的参数</span></span><br><span class="line"><span class="comment">   * <span class="doctag">@returns <span class="type">&#123;*&#125;</span></span></span></span><br><span class="line"><span class="comment">   */</span></span><br><span class="line">  getParameters: <span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span><br><span class="line">    <span class="keyword">var</span> params = sessionStorage.getItem(<span class="string">"_parameters"</span>);</span><br><span class="line">    sessionStorage.removeItem(<span class="string">"_parameters"</span>);</span><br><span class="line">    <span class="comment">//params = Za.isEmpty(params) ? &#123;&#125; : params;</span></span><br><span class="line">    <span class="keyword">return</span> Za.JsonEval(params);</span><br><span class="line">  &#125;,</span><br><span class="line"></span><br><span class="line">  <span class="comment">/**</span></span><br><span class="line"><span class="comment">   * 清空 页面间跳转的参数</span></span><br><span class="line"><span class="comment">   */</span></span><br><span class="line">  clearParameters: <span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span><br><span class="line">    sessionStorage.removeItem(<span class="string">"_parameters"</span>);</span><br><span class="line">  &#125;,</span><br><span class="line"></span><br><span class="line">  <span class="comment">/**</span></span><br><span class="line"><span class="comment">   * 查询当前日前几天的日期</span></span><br><span class="line"><span class="comment">   * <span class="doctag">@param </span>AddDayCount &#123;int&#125; 负数为前X天 正数为后X天</span></span><br><span class="line"><span class="comment">   * <span class="doctag">@returns <span class="type">&#123;string&#125;</span></span></span></span><br><span class="line"><span class="comment">   * <span class="doctag">@exaple</span></span></span><br><span class="line"><span class="comment">   *    Za.getDate(-6)</span></span><br><span class="line"><span class="comment">   */</span></span><br><span class="line">  getDate: <span class="function"><span class="keyword">function</span> (<span class="params">AddDayCount</span>) </span>&#123; <span class="comment">//日期查询</span></span><br><span class="line">    <span class="keyword">var</span> dd = <span class="keyword">new</span> <span class="built_in">Date</span>();</span><br><span class="line">    dd.setDate(dd.getDate() + AddDayCount + <span class="number">1</span>);</span><br><span class="line">    <span class="keyword">var</span> y = dd.getYear() + <span class="number">1900</span>;</span><br><span class="line">    <span class="keyword">var</span> m = (dd.getMonth() + <span class="number">1</span>) &lt; <span class="number">10</span> ? <span class="string">"0"</span> + (dd.getMonth() + <span class="number">1</span>) : (dd.getMonth() + <span class="number">1</span>);</span><br><span class="line">    <span class="keyword">var</span> d = dd.getDate() &lt; <span class="number">10</span> ? <span class="string">"0"</span> + dd.getDate() : dd.getDate();</span><br><span class="line">    <span class="keyword">return</span> y + <span class="string">"-"</span> + m + <span class="string">"-"</span> + d;</span><br><span class="line">  &#125;,</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">  <span class="comment">/**</span></span><br><span class="line"><span class="comment">   * JSON对象转换为String</span></span><br><span class="line"><span class="comment">   * <span class="doctag">@param <span class="variable">json</span></span></span></span><br><span class="line"><span class="comment">   * <span class="doctag">@constructor</span></span></span><br><span class="line"><span class="comment">   */</span></span><br><span class="line">  JsonToStr: <span class="function"><span class="keyword">function</span> (<span class="params">json</span>) </span>&#123;</span><br><span class="line">    <span class="keyword">return</span> <span class="built_in">JSON</span>.stringify(json);</span><br><span class="line">  &#125;,</span><br><span class="line">  <span class="comment">/**</span></span><br><span class="line"><span class="comment">   * String转换为JSON</span></span><br><span class="line"><span class="comment">   * <span class="doctag">@param <span class="variable">str</span></span></span></span><br><span class="line"><span class="comment">   * <span class="doctag">@returns <span class="type">&#123;Object&#125;</span></span></span></span><br><span class="line"><span class="comment">   * <span class="doctag">@constructor</span></span></span><br><span class="line"><span class="comment">   */</span></span><br><span class="line">  JsonEval: <span class="function"><span class="keyword">function</span> (<span class="params">str</span>) </span>&#123;</span><br><span class="line">    <span class="keyword">return</span> <span class="built_in">eval</span>(<span class="string">"("</span> + str + <span class="string">")"</span>);</span><br><span class="line">    <span class="comment">//return JSON.parse(str);</span></span><br><span class="line">  &#125;,</span><br><span class="line"></span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line"><span class="keyword">export</span> <span class="keyword">default</span> Za</span><br></pre></td></tr></table></figure>


      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://dttx123.gitee.io/2017/05/05/JQuery/JQuery/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/blog/images/avatar.jpg">
      <meta itemprop="name" content="大春哥">
      <meta itemprop="description" content="IT">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Starry Night">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/blog/2017/05/05/JQuery/JQuery/" class="post-title-link" itemprop="url">JQuery基础</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2017-05-05 00:00:00" itemprop="dateCreated datePublished" datetime="2017-05-05T00:00:00+08:00">2017-05-05</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2020-05-13 08:44:40" itemprop="dateModified" datetime="2020-05-13T08:44:40+08:00">2020-05-13</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/JQuery/" itemprop="url" rel="index"><span itemprop="name">JQuery</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h1 id="jQuery基本介绍"><a href="#jQuery基本介绍" class="headerlink" title="jQuery基本介绍"></a>jQuery基本介绍</h1><h2 id="为什么要学jQuery"><a href="#为什么要学jQuery" class="headerlink" title="为什么要学jQuery"></a>为什么要学jQuery</h2><p>使用JS操作DOM的时候，会遇到以下的一些缺点：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//1. 获取元素的方法太少且长，麻烦。</span></span><br><span class="line"><span class="comment">//2. 遍历伪数组很麻烦，通常要嵌套一大堆的for循环。</span></span><br><span class="line"><span class="comment">//3. 注册的事件会覆盖。</span></span><br><span class="line"><span class="comment">//4. 有兼容性问题。</span></span><br><span class="line"><span class="comment">//5. 实现动画很麻烦</span></span><br></pre></td></tr></table></figure>
          <!--noindex-->
            <div class="post-button">
              <a class="btn" href="/blog/2017/05/05/JQuery/JQuery/#more" rel="contents">
                阅读全文 &raquo;
              </a>
            </div>
          <!--/noindex-->
        
      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://dttx123.gitee.io/2017/04/03/javaScript/%E5%87%BD%E6%95%B0/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/blog/images/avatar.jpg">
      <meta itemprop="name" content="大春哥">
      <meta itemprop="description" content="IT">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Starry Night">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/blog/2017/04/03/javaScript/%E5%87%BD%E6%95%B0/" class="post-title-link" itemprop="url">函数基础</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2017-04-03 00:00:00" itemprop="dateCreated datePublished" datetime="2017-04-03T00:00:00+08:00">2017-04-03</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2020-05-13 00:26:02" itemprop="dateModified" datetime="2020-05-13T00:26:02+08:00">2020-05-13</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/js%E5%9F%BA%E7%A1%80/" itemprop="url" rel="index"><span itemprop="name">js基础</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h1 id="函数"><a href="#函数" class="headerlink" title="函数"></a>函数</h1><h2 id="定义函数的三种方式"><a href="#定义函数的三种方式" class="headerlink" title="定义函数的三种方式"></a>定义函数的三种方式</h2><h3 id="函数声明"><a href="#函数声明" class="headerlink" title="函数声明"></a>函数声明</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">fn();<span class="comment">//函数声明可以先调用，在声明</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">fn</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">  <span class="built_in">console</span>.log(<span class="string">"这是函数声明"</span>)</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="函数表达式"><a href="#函数表达式" class="headerlink" title="函数表达式"></a>函数表达式</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> fn = <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">  <span class="built_in">console</span>.log(<span class="string">"这是函数表达式"</span>);  </span><br><span class="line">&#125;</span><br><span class="line">fn();<span class="comment">//函数表达式必须先声明，再调用</span></span><br></pre></td></tr></table></figure>
          <!--noindex-->
            <div class="post-button">
              <a class="btn" href="/blog/2017/04/03/javaScript/%E5%87%BD%E6%95%B0/#more" rel="contents">
                阅读全文 &raquo;
              </a>
            </div>
          <!--/noindex-->
        
      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://dttx123.gitee.io/2017/03/20/javaScript/%E6%AD%A3%E5%88%99%E5%9F%BA%E7%A1%80%E5%92%8CJQuery%E5%B0%81%E8%A3%85/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/blog/images/avatar.jpg">
      <meta itemprop="name" content="大春哥">
      <meta itemprop="description" content="IT">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Starry Night">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/blog/2017/03/20/javaScript/%E6%AD%A3%E5%88%99%E5%9F%BA%E7%A1%80%E5%92%8CJQuery%E5%B0%81%E8%A3%85/" class="post-title-link" itemprop="url">正则和jq封装</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2017-03-20 00:00:00" itemprop="dateCreated datePublished" datetime="2017-03-20T00:00:00+08:00">2017-03-20</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2020-05-13 00:26:12" itemprop="dateModified" datetime="2020-05-13T00:26:12+08:00">2020-05-13</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/js%E5%9F%BA%E7%A1%80/" itemprop="url" rel="index"><span itemprop="name">js基础</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h1 id="正则表达式"><a href="#正则表达式" class="headerlink" title="正则表达式"></a>正则表达式</h1><blockquote>
<p>正则表达式：用于匹配规律规则的表达式，正则表达式最初是科学家对人类神经系统的工作原理的早期研究，现在在编程语言中有广泛的应用，经常用于表单校验，高级搜索等。</p>
</blockquote>
          <!--noindex-->
            <div class="post-button">
              <a class="btn" href="/blog/2017/03/20/javaScript/%E6%AD%A3%E5%88%99%E5%9F%BA%E7%A1%80%E5%92%8CJQuery%E5%B0%81%E8%A3%85/#more" rel="contents">
                阅读全文 &raquo;
              </a>
            </div>
          <!--/noindex-->
        
      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://dttx123.gitee.io/2017/02/07/javaScript/%E5%AF%B9%E8%B1%A1%E5%92%8C%E5%8E%9F%E5%9E%8B/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/blog/images/avatar.jpg">
      <meta itemprop="name" content="大春哥">
      <meta itemprop="description" content="IT">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Starry Night">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/blog/2017/02/07/javaScript/%E5%AF%B9%E8%B1%A1%E5%92%8C%E5%8E%9F%E5%9E%8B/" class="post-title-link" itemprop="url">js对象和原型</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2017-02-07 00:00:00" itemprop="dateCreated datePublished" datetime="2017-02-07T00:00:00+08:00">2017-02-07</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2020-05-13 10:43:06" itemprop="dateModified" datetime="2020-05-13T10:43:06+08:00">2020-05-13</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/js%E5%9F%BA%E7%A1%80/" itemprop="url" rel="index"><span itemprop="name">js基础</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h2 id="typeof关键字"><a href="#typeof关键字" class="headerlink" title="typeof关键字"></a><code>typeof</code>关键字</h2><p><code>typeof</code>操作符返回一个<strong>字符串</strong>,返回的是操作数的类型</p>
<ul>
<li><code>typeof 基本类型</code>返回的是字符串</li>
<li><code>typeof 对象</code> 返回的是object</li>
</ul>
<ul>
<li><code>typeof 函数</code> 返回的是function</li>
<li><code>typeof null</code> 返回的object</li>
</ul>
          <!--noindex-->
            <div class="post-button">
              <a class="btn" href="/blog/2017/02/07/javaScript/%E5%AF%B9%E8%B1%A1%E5%92%8C%E5%8E%9F%E5%9E%8B/#more" rel="contents">
                阅读全文 &raquo;
              </a>
            </div>
          <!--/noindex-->
        
      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://dttx123.gitee.io/2017/02/04/javaScript/%E9%97%AD%E5%8C%85%E5%92%8C%E7%BB%A7%E6%89%BF/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/blog/images/avatar.jpg">
      <meta itemprop="name" content="大春哥">
      <meta itemprop="description" content="IT">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Starry Night">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/blog/2017/02/04/javaScript/%E9%97%AD%E5%8C%85%E5%92%8C%E7%BB%A7%E6%89%BF/" class="post-title-link" itemprop="url">闭包和继承</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2017-02-04 00:00:00" itemprop="dateCreated datePublished" datetime="2017-02-04T00:00:00+08:00">2017-02-04</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2020-05-13 08:44:42" itemprop="dateModified" datetime="2020-05-13T08:44:42+08:00">2020-05-13</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/js%E5%9F%BA%E7%A1%80/" itemprop="url" rel="index"><span itemprop="name">js基础</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h1 id="闭包"><a href="#闭包" class="headerlink" title="闭包"></a>闭包</h1><h2 id="闭包的基本概念"><a href="#闭包的基本概念" class="headerlink" title="闭包的基本概念"></a>闭包的基本概念</h2><p><code>闭包（closure）</code>是JavaScript语言的一个难点，也是JavaScript的一个特色，很多高级的应用都要依靠闭包来实现。</p>
          <!--noindex-->
            <div class="post-button">
              <a class="btn" href="/blog/2017/02/04/javaScript/%E9%97%AD%E5%8C%85%E5%92%8C%E7%BB%A7%E6%89%BF/#more" rel="contents">
                阅读全文 &raquo;
              </a>
            </div>
          <!--/noindex-->
        
      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://dttx123.gitee.io/2016/12/23/webAPI/08/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/blog/images/avatar.jpg">
      <meta itemprop="name" content="大春哥">
      <meta itemprop="description" content="IT">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Starry Night">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/blog/2016/12/23/webAPI/08/" class="post-title-link" itemprop="url">webAPI08</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2016-12-23 00:00:00" itemprop="dateCreated datePublished" datetime="2016-12-23T00:00:00+08:00">2016-12-23</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2020-05-13 11:03:54" itemprop="dateModified" datetime="2020-05-13T11:03:54+08:00">2020-05-13</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/dom%E6%93%8D%E4%BD%9C/" itemprop="url" rel="index"><span itemprop="name">dom操作</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h1 id="移动端"><a href="#移动端" class="headerlink" title="移动端"></a>移动端</h1><h2 id="类名操作"><a href="#类名操作" class="headerlink" title="类名操作"></a>类名操作</h2><blockquote>
<p>推荐：classList是一个集合，会存储某个元素上所有的类名，使用classList来替代className操作class类</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//添加类</span></span><br><span class="line">node.classList.add(<span class="string">"classname"</span>);</span><br><span class="line"><span class="comment">//移除类</span></span><br><span class="line">node.classList.remove(<span class="string">"classname"</span>);</span><br><span class="line"><span class="comment">//切换类</span></span><br><span class="line">node.classList.toggle(<span class="string">"classname"</span>);</span><br><span class="line"><span class="comment">//判断类</span></span><br><span class="line">node.classList.contains(<span class="string">"classname"</span>);</span><br></pre></td></tr></table></figure>

<h2 id="touch事件"><a href="#touch事件" class="headerlink" title="touch事件"></a>touch事件</h2><p>移动端新增了4个与手指触摸相关的事件。</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//touchstart:手指放到屏幕上时触发</span></span><br><span class="line"><span class="comment">//touchmove:手指在屏幕上滑动式触发（会触发多次）</span></span><br><span class="line"><span class="comment">//touchend:手指离开屏幕时触发</span></span><br><span class="line"><span class="comment">//touchcancel:系统取消touch事件的时候触发,比如电话</span></span><br></pre></td></tr></table></figure>

<p>每个触摸事件被触发后，会生成一个event对象，event对象中<code>changedTouches</code>会记录手指滑动的信息。</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">e.touches;<span class="comment">//当前屏幕上的手指</span></span><br><span class="line">e.targetTouches;<span class="comment">//当前dom元素上的手指。</span></span><br><span class="line">e.changedTouches;<span class="comment">//触摸时发生改变的手指。(重点)</span></span><br></pre></td></tr></table></figure>

<p>这些列表里的每次触摸由touch对象组成，touch对象里包含着触摸信息，主要属性如下</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">clientX / clientY: <span class="comment">//触摸点相对浏览器窗口的位置</span></span><br><span class="line">pageX / pageY:     <span class="comment">//触摸点相对于页面的位置</span></span><br></pre></td></tr></table></figure>

<h2 id="区域滚动与iscroll"><a href="#区域滚动与iscroll" class="headerlink" title="区域滚动与iscroll"></a>区域滚动与iscroll</h2>
      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://dttx123.gitee.io/2016/11/03/webAPI/07/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/blog/images/avatar.jpg">
      <meta itemprop="name" content="大春哥">
      <meta itemprop="description" content="IT">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Starry Night">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/blog/2016/11/03/webAPI/07/" class="post-title-link" itemprop="url">webAPI07</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2016-11-03 00:00:00" itemprop="dateCreated datePublished" datetime="2016-11-03T00:00:00+08:00">2016-11-03</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2020-05-13 11:05:05" itemprop="dateModified" datetime="2020-05-13T11:05:05+08:00">2020-05-13</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/dom%E6%93%8D%E4%BD%9C/" itemprop="url" rel="index"><span itemprop="name">dom操作</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h1 id="动画函数封装"><a href="#动画函数封装" class="headerlink" title="动画函数封装"></a>动画函数封装</h1><h2 id="动画初体验-实现div到left-400的位置"><a href="#动画初体验-实现div到left-400的位置" class="headerlink" title="动画初体验-实现div到left=400的位置"></a>动画初体验-实现div到left=400的位置</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">点击按钮，让div能够移动到<span class="number">400</span>的位置，到达终点，清除定时器</span><br></pre></td></tr></table></figure>

<h2 id="动画初体验-让div做多个动画"><a href="#动画初体验-让div做多个动画" class="headerlink" title="动画初体验-让div做多个动画"></a>动画初体验-让div做多个动画</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">点击按钮<span class="number">1</span>，让div能够移动到<span class="number">400</span>的位置，到达终点，清除定时器</span><br><span class="line">点击按钮<span class="number">2</span>，让div能够移动到<span class="number">800</span>的位置，到达终点，清除定时器</span><br><span class="line">还要让div能够从<span class="number">800</span> 移动到<span class="number">400</span>的位置，到达终点，清除定时器</span><br></pre></td></tr></table></figure>

<h2 id="动画初体验-div到达终点"><a href="#动画初体验-div到达终点" class="headerlink" title="动画初体验-div到达终点"></a>动画初体验-div到达终点</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">让div移动到<span class="number">96</span>px的位置，发现元素不能移动到终点位置</span><br></pre></td></tr></table></figure>

<h2 id="动画初体验-清除多个定时器"><a href="#动画初体验-清除多个定时器" class="headerlink" title="动画初体验-清除多个定时器"></a>动画初体验-清除多个定时器</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">点击元素多次，会发现元素会左右来回移动，到达不了终点。</span><br></pre></td></tr></table></figure>



<h1 id="短路运算"><a href="#短路运算" class="headerlink" title="短路运算"></a>短路运算</h1><p>&amp;&amp;：短路与， 只要碰到了false，就会短路，短路后不会执行第二个表达式。</p>
<p>||：短路或，只要碰到了true就会短路，短路后不会执行第二个表达式。</p>
<p><strong>注意：&amp;&amp;和||的结果不一定是布尔类型，也可以是其他的类型</strong></p>
<p><strong>||经常用来给函数设置默认值</strong></p>
<h1 id="轮播图"><a href="#轮播图" class="headerlink" title="轮播图"></a>轮播图</h1><h2 id="简单轮播图"><a href="#简单轮播图" class="headerlink" title="简单轮播图"></a>简单轮播图</h2><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span> 结构分析</span><br><span class="line"><span class="number">2.</span> 按钮高亮以及排他</span><br><span class="line"><span class="number">3.</span> 移动图片：渐渐的移动图片，用到animate函数</span><br></pre></td></tr></table></figure>



<h2 id="左右焦点图"><a href="#左右焦点图" class="headerlink" title="左右焦点图"></a>左右焦点图</h2><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span>结构分析</span><br><span class="line"><span class="number">2.</span>左右箭头的显示与隐藏</span><br><span class="line"><span class="number">3.</span>点击左箭头与右箭头（下标判断）</span><br></pre></td></tr></table></figure>



<h2 id="无缝轮播图"><a href="#无缝轮播图" class="headerlink" title="无缝轮播图"></a>无缝轮播图</h2><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span> 需要添加假图片</span><br><span class="line"><span class="number">2.</span> 真图片与假图片之间互相切换。</span><br></pre></td></tr></table></figure>



<h2 id="完整版轮播图"><a href="#完整版轮播图" class="headerlink" title="完整版轮播图"></a>完整版轮播图</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span> js动态添加小圆点</span><br><span class="line"><span class="number">2.</span> js动态添加最后一张假图片</span><br><span class="line"><span class="number">3.</span> 实现左右焦点图 + 无缝滚动</span><br><span class="line"><span class="number">4.</span> 自动播放</span><br><span class="line"><span class="number">5.</span> 点击小圆点同步切换</span><br><span class="line"><span class="number">6.</span> 解决点击小圆点的bug</span><br></pre></td></tr></table></figure>





<h1 id="三大家族"><a href="#三大家族" class="headerlink" title="三大家族"></a>三大家族</h1><h2 id="offset家族"><a href="#offset家族" class="headerlink" title="offset家族"></a>offset家族</h2><blockquote>
<p>offset系列用于用于获取元素自身的大小和位置，在网页特效中有广泛应用</p>
<p>offset系列主要有：offsetHeight、offsetWidth、offsetParent、offsetLeft、offsetTop</p>
</blockquote>
<p>offsetHeight与offsetWidth</p>
<ol>
<li>获取的是元素真实的高度和宽度</li>
<li>获取到的是数值类型，方便计算</li>
<li>offsetHeight与offsetWidth是只读属性，不能设置。</li>
</ol>
<p>offsetHeight与offsetWidth的构成</p>
<p>​    offsetHeight = height + paddnig + border</p>
<p>​    offsetWidth = width + padding + border</p>
<p> <img src="/blog/2016/11/03/webAPI/07/offset.png" alt="offset"></p>
<h2 id="scroll家族"><a href="#scroll家族" class="headerlink" title="scroll家族"></a>scroll家族</h2><blockquote>
<p>scroll家族用来获取盒子内容的大小和位置</p>
<p>scroll家族有：scrollWidth、scrollHeight、scrollLeft、scrollTop</p>
</blockquote>
<ol>
<li><p>scrollWidth与scrollHeight是盒子内容的真实的宽度和高度。与和盒子大小无关，仅仅与盒子的内容有关系。</p>
</li>
<li><p>scrollTop用于获取内容垂直滚动的像素数。如果没有滚动条，那么scrollTop值是0</p>
<p><img src="/blog/2016/11/03/webAPI/07/scroll.png" alt="scroll"></p>
</li>
</ol>
<p>onscroll事件，对于有滚动条的盒子，可以使用onscroll注册滚动事件，每滚动一像素，就会触发该事件。</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> box = doucment.getElementById(“box”);</span><br><span class="line">box.onscroll = <span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">	<span class="comment">//事件处理程序</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>获取页面被卷去的高度和宽度</p>
<blockquote>
<p>通常来说，scroll家族用的最多的地方就是用来获取页面被卷去的宽度和高度，非常的常用</p>
</blockquote>
<p>页面被卷去的高度和宽度</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">window</span>.onscroll = <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">  <span class="keyword">var</span> scrollTop = <span class="built_in">window</span>.pageYOffset</span><br><span class="line">  <span class="keyword">var</span> scrollLeft = <span class="built_in">window</span>.pageXOffset</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>【仿腾讯固定导航案例.html】</p>
<h2 id="client家族"><a href="#client家族" class="headerlink" title="client家族"></a>client家族</h2><blockquote>
<p>client家族用于获取盒子可视区的大小</p>
<p>client家族有clientWidth、clientHeight、clientLeft、clientTop</p>
</blockquote>
<p>clietnWidth: 获取内容和padding的大小</p>
<p>clientHeight:获取内容与padding的大小</p>
<blockquote>
<p>clientTop与clientLeft</p>
</blockquote>
<p><strong>clientTop</strong>与<strong>clientLeft</strong> 完全没有用，他们就是borderTop与borderLeft</p>
<p> <img src="/blog/2016/11/03/webAPI/07/client1.png" alt="client1"></p>
<blockquote>
<p>三大家族对比</p>
</blockquote>
<p> <img src="/blog/2016/11/03/webAPI/07/client.png" alt="client"></p>
<blockquote>
<p>onresize事件：onresize事件会在窗口被调整大小的时候发生。</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">window</span>.onresize = <span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">	<span class="comment">//事件处理程序</span></span><br><span class="line">    <span class="keyword">var</span> width = <span class="built_in">window</span>.innerWidth;</span><br><span class="line">    <span class="keyword">var</span> height = <span class="built_in">window</span>.innerHeight</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://dttx123.gitee.io/2016/10/03/webAPI/06/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/blog/images/avatar.jpg">
      <meta itemprop="name" content="大春哥">
      <meta itemprop="description" content="IT">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Starry Night">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/blog/2016/10/03/webAPI/06/" class="post-title-link" itemprop="url">webAPI06</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2016-10-03 00:00:00" itemprop="dateCreated datePublished" datetime="2016-10-03T00:00:00+08:00">2016-10-03</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2020-05-13 11:04:52" itemprop="dateModified" datetime="2020-05-13T11:04:52+08:00">2020-05-13</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/dom%E6%93%8D%E4%BD%9C/" itemprop="url" rel="index"><span itemprop="name">dom操作</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h1 id="BOM"><a href="#BOM" class="headerlink" title="BOM"></a>BOM</h1><blockquote>
<p>BOM（Browser Object Model）：浏览器对象模型，提供了一套操作浏览器功能的工具。</p>
</blockquote>
<p> <img src="/blog/2016/10/03/webAPI/06/images%5C1.png" alt="1"></p>
<p>BOM包含的内容很多，但是很多东西都不太常用，在BOM中需要大家掌握的就一个东西，那就是<strong><em>定时器</em></strong> 。</p>
<h2 id="window对象"><a href="#window对象" class="headerlink" title="window对象"></a>window对象</h2><ol>
<li>window对象是一个全局对象，也可以说是JavaScript中的顶级对象</li>
<li>像document、alert()、console.log()这些都是window的属性，其实BOM中基本所有的属性和方法都是属性window的。</li>
<li>所有定义在全局作用域中的变量、函数都会变成window对象的属性和方法</li>
<li>window对象下的属性和方法调用的时候可以省略window</li>
</ol>
<h3 id="window-onload（掌握）"><a href="#window-onload（掌握）" class="headerlink" title="window.onload（掌握）"></a>window.onload（掌握）</h3><blockquote>
<p>window.onload事件会在窗体加载完成后执行，通常我们称之为入口函数。</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">window</span>.onload = <span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">	<span class="comment">//里面的代码会在窗体加载完成后执行。</span></span><br><span class="line">	<span class="comment">//窗体加载完成包括文档树的加载、还有图片、文件的加载完成。</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>思考：一个页面能不能写两个window.onload?</p>
<h2 id="延时器与定时器"><a href="#延时器与定时器" class="headerlink" title="延时器与定时器"></a>延时器与定时器</h2><h3 id="setTimeout"><a href="#setTimeout" class="headerlink" title="setTimeout"></a>setTimeout</h3><blockquote>
<p>setTimeout延时器可以在延迟时间到期后执行一个指定的函数。</p>
</blockquote>
<p>设置延时器</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//语法：setTimeOut(callback, time);</span></span><br><span class="line"><span class="comment">//参数1：回调函数，时间到了就会执行。</span></span><br><span class="line"><span class="comment">//参数2：延时的时间</span></span><br><span class="line"><span class="comment">//返回：定时器的id，用于清除</span></span><br><span class="line"><span class="comment">//示例：</span></span><br><span class="line"><span class="keyword">var</span> timer = setTimeOut(<span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">	<span class="comment">//1秒后将执行的代码。</span></span><br><span class="line">&#125;, <span class="number">1000</span>);</span><br></pre></td></tr></table></figure>

<p>清除延时器</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//语法：clearTimeOut(timerId)</span></span><br><span class="line"><span class="comment">//参数：定时器id</span></span><br><span class="line"><span class="comment">//示例：</span></span><br><span class="line">clearTimeOut(timer);<span class="comment">//清除上面定义的定时器</span></span><br></pre></td></tr></table></figure>

<h3 id="setInterval"><a href="#setInterval" class="headerlink" title="setInterval"></a>setInterval</h3><blockquote>
<p>setInterval,方法重复调用一个函数或执行一个代码段，在每次调用之间具有固定的时间延迟。定时器除非清除，否则会一直执行下去。</p>
</blockquote>
<p>设置定时器</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//语法：var intervalID = setInterval(func, delay);</span></span><br><span class="line"><span class="comment">//参数1：重复执行的函数</span></span><br><span class="line"><span class="comment">//参数2：每次延迟的毫秒数</span></span><br><span class="line"><span class="comment">//返回：定时器的id，用于清除</span></span><br><span class="line"><span class="comment">//示例：</span></span><br><span class="line"><span class="keyword">var</span> timer = setInterval(<span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">	<span class="comment">//重复执行的代码。</span></span><br><span class="line">&#125;, <span class="number">1000</span>);</span><br></pre></td></tr></table></figure>

<p>清除定时器</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//语法：clearInterval(intervalID)</span></span><br><span class="line"><span class="comment">//参数：定时器id</span></span><br><span class="line"><span class="comment">//示例：</span></span><br><span class="line">clearInterval(timer);<span class="comment">//清除上面定义的定时器</span></span><br></pre></td></tr></table></figure>

<h3 id="案例"><a href="#案例" class="headerlink" title="案例"></a>案例</h3><p>【电子表】</p>
<p>【短信验证码案例.html】</p>
<h2 id="location对象"><a href="#location对象" class="headerlink" title="location对象"></a>location对象</h2><blockquote>
<p>location对象也是window的一个属性，location其实对应的就是浏览器中的地址栏。</p>
</blockquote>
<h3 id="常用属性和方法"><a href="#常用属性和方法" class="headerlink" title="常用属性和方法"></a>常用属性和方法</h3><blockquote>
<p>location.href:控制地址栏中的地址</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">location.href = “http:<span class="comment">//www.baidu.com”;//让页面跳转到百度首页</span></span><br><span class="line"><span class="built_in">console</span>.log(<span class="built_in">window</span>.location.search);<span class="comment">//参数</span></span><br></pre></td></tr></table></figure>

<blockquote>
<p>location.reload()：让页面重新加载</p>
</blockquote>
<p>【案例：定时跳转.html】</p>
<h2 id="navigator对象"><a href="#navigator对象" class="headerlink" title="navigator对象"></a>navigator对象</h2><blockquote>
<p>window.navigator的一些属性可以获取客户端的一些信息</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//navigator.userAgent：浏览器版本</span></span><br></pre></td></tr></table></figure>

<h2 id="history对象"><a href="#history对象" class="headerlink" title="history对象"></a>history对象</h2><p>history对象表示页面的历史</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//后退：</span></span><br><span class="line">history.back();</span><br><span class="line">history.go(<span class="number">-1</span>);</span><br><span class="line"><span class="comment">//前进：</span></span><br><span class="line">history.forward();</span><br><span class="line">history.go(<span class="number">1</span>);</span><br></pre></td></tr></table></figure>






      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://dttx123.gitee.io/2016/09/03/webAPI/05/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/blog/images/avatar.jpg">
      <meta itemprop="name" content="大春哥">
      <meta itemprop="description" content="IT">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Starry Night">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/blog/2016/09/03/webAPI/05/" class="post-title-link" itemprop="url">webAPI05</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2016-09-03 00:00:00" itemprop="dateCreated datePublished" datetime="2016-09-03T00:00:00+08:00">2016-09-03</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2020-05-13 11:04:50" itemprop="dateModified" datetime="2020-05-13T11:04:50+08:00">2020-05-13</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/dom%E6%93%8D%E4%BD%9C/" itemprop="url" rel="index"><span itemprop="name">dom操作</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h1 id="BOM"><a href="#BOM" class="headerlink" title="BOM"></a>BOM</h1><blockquote>
<p>BOM（Browser Object Model）：浏览器对象模型，提供了一套操作浏览器功能的工具。</p>
</blockquote>
<p> <img src="/blog/2016/09/03/webAPI/05/images%5C1.png" alt="1"></p>
<p>BOM包含的内容很多，但是很多东西都不太常用，在BOM中需要大家掌握的就一个东西，那就是<strong><em>定时器</em></strong> 。</p>
<h2 id="window对象"><a href="#window对象" class="headerlink" title="window对象"></a>window对象</h2><ol>
<li>window对象是一个全局对象，也可以说是JavaScript中的顶级对象</li>
<li>像document、alert()、console.log()这些都是window的属性，其实BOM中基本所有的属性和方法都是属性window的。</li>
<li>所有定义在全局作用域中的变量、函数都会变成window对象的属性和方法</li>
<li>window对象下的属性和方法调用的时候可以省略window</li>
</ol>
<h3 id="window-onload（掌握）"><a href="#window-onload（掌握）" class="headerlink" title="window.onload（掌握）"></a>window.onload（掌握）</h3><blockquote>
<p>window.onload事件会在窗体加载完成后执行，通常我们称之为入口函数。</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">window</span>.onload = <span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">	<span class="comment">//里面的代码会在窗体加载完成后执行。</span></span><br><span class="line">	<span class="comment">//窗体加载完成包括文档树的加载、还有图片、文件的加载完成。</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>思考：一个页面能不能写两个window.onload?</p>
<h2 id="延时器与定时器"><a href="#延时器与定时器" class="headerlink" title="延时器与定时器"></a>延时器与定时器</h2><h3 id="setTimeout"><a href="#setTimeout" class="headerlink" title="setTimeout"></a>setTimeout</h3><blockquote>
<p>setTimeout延时器可以在延迟时间到期后执行一个指定的函数。</p>
</blockquote>
<p>设置延时器</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//语法：setTimeOut(callback, time);</span></span><br><span class="line"><span class="comment">//参数1：回调函数，时间到了就会执行。</span></span><br><span class="line"><span class="comment">//参数2：延时的时间</span></span><br><span class="line"><span class="comment">//返回：定时器的id，用于清除</span></span><br><span class="line"><span class="comment">//示例：</span></span><br><span class="line"><span class="keyword">var</span> timer = setTimeOut(<span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">	<span class="comment">//1秒后将执行的代码。</span></span><br><span class="line">&#125;, <span class="number">1000</span>);</span><br></pre></td></tr></table></figure>

<p>清除延时器</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//语法：clearTimeOut(timerId)</span></span><br><span class="line"><span class="comment">//参数：定时器id</span></span><br><span class="line"><span class="comment">//示例：</span></span><br><span class="line">clearTimeOut(timer);<span class="comment">//清除上面定义的定时器</span></span><br></pre></td></tr></table></figure>

<h3 id="setInterval"><a href="#setInterval" class="headerlink" title="setInterval"></a>setInterval</h3><blockquote>
<p>setInterval,方法重复调用一个函数或执行一个代码段，在每次调用之间具有固定的时间延迟。定时器除非清除，否则会一直执行下去。</p>
</blockquote>
<p>设置定时器</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//语法：var intervalID = setInterval(func, delay);</span></span><br><span class="line"><span class="comment">//参数1：重复执行的函数</span></span><br><span class="line"><span class="comment">//参数2：每次延迟的毫秒数</span></span><br><span class="line"><span class="comment">//返回：定时器的id，用于清除</span></span><br><span class="line"><span class="comment">//示例：</span></span><br><span class="line"><span class="keyword">var</span> timer = setInterval(<span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">	<span class="comment">//重复执行的代码。</span></span><br><span class="line">&#125;, <span class="number">1000</span>);</span><br></pre></td></tr></table></figure>

<p>清除定时器</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//语法：clearInterval(intervalID)</span></span><br><span class="line"><span class="comment">//参数：定时器id</span></span><br><span class="line"><span class="comment">//示例：</span></span><br><span class="line">clearInterval(timer);<span class="comment">//清除上面定义的定时器</span></span><br></pre></td></tr></table></figure>

<h3 id="案例"><a href="#案例" class="headerlink" title="案例"></a>案例</h3><p>【电子表】</p>
<p>【短信验证码案例.html】</p>
<h2 id="location对象"><a href="#location对象" class="headerlink" title="location对象"></a>location对象</h2><blockquote>
<p>location对象也是window的一个属性，location其实对应的就是浏览器中的地址栏。</p>
</blockquote>
<h3 id="常用属性和方法"><a href="#常用属性和方法" class="headerlink" title="常用属性和方法"></a>常用属性和方法</h3><blockquote>
<p>location.href:控制地址栏中的地址</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">location.href = “http:<span class="comment">//www.baidu.com”;//让页面跳转到百度首页</span></span><br><span class="line"><span class="built_in">console</span>.log(<span class="built_in">window</span>.location.search);<span class="comment">//参数</span></span><br></pre></td></tr></table></figure>

<blockquote>
<p>location.reload()：让页面重新加载</p>
</blockquote>
<p>【案例：定时跳转.html】</p>
<h2 id="navigator对象"><a href="#navigator对象" class="headerlink" title="navigator对象"></a>navigator对象</h2><blockquote>
<p>window.navigator的一些属性可以获取客户端的一些信息</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//navigator.userAgent：浏览器版本</span></span><br></pre></td></tr></table></figure>

<h2 id="history对象"><a href="#history对象" class="headerlink" title="history对象"></a>history对象</h2><p>history对象表示页面的历史</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//后退：</span></span><br><span class="line">history.back();</span><br><span class="line">history.go(<span class="number">-1</span>);</span><br><span class="line"><span class="comment">//前进：</span></span><br><span class="line">history.forward();</span><br><span class="line">history.go(<span class="number">1</span>);</span><br></pre></td></tr></table></figure>






      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  


  
  <nav class="pagination">
    <a class="extend prev" rel="prev" href="/blog/page/2/"><i class="fa fa-angle-left" aria-label="上一页"></i></a><a class="page-number" href="/blog/">1</a><a class="page-number" href="/blog/page/2/">2</a><span class="page-number current">3</span><a class="page-number" href="/blog/page/4/">4</a><a class="extend next" rel="next" href="/blog/page/4/"><i class="fa fa-angle-right" aria-label="下一页"></i></a>
  </nav>



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="大春哥"
      src="/blog/images/avatar.jpg">
  <p class="site-author-name" itemprop="name">大春哥</p>
  <div class="site-description" itemprop="description">IT</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/blog/archives/">
        
          <span class="site-state-item-count">35</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/blog/categories/">
          
        <span class="site-state-item-count">11</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/blog/tags/">
          
        <span class="site-state-item-count">17</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">大春哥</span>
</div>

        








      </div>
    </footer>
  </div>

  
  <script src="/blog/lib/anime.min.js"></script>
  <script src="/blog/lib/velocity/velocity.min.js"></script>
  <script src="/blog/lib/velocity/velocity.ui.min.js"></script>

<script src="/blog/js/utils.js"></script>

<script src="/blog/js/motion.js"></script>


<script src="/blog/js/schemes/pisces.js"></script>


<script src="/blog/js/next-boot.js"></script>




  




  
<script src="/blog/js/local-search.js"></script>













  

  

</body>
</html>
